package logic

import (
	"context"
	"order/api/internal/svc"
	"order/api/internal/types"
	"order/api/internal/utils"
	"order/orderrpc/orderrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProductAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewProductAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductAddLogic {
	return &ProductAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ProductAddLogic) ProductAdd(req *types.ProductAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.OrderRpc.ProductAdd(l.ctx, &orderrpc.ProductAddRequest{
		Title:  req.Title,
		Stock:  req.Stock,
		Price:  float32(req.Price),
		Image:  req.Image,
		Info:   req.Info,
		UserId: req.UserId,
	})
	if err != nil {
		return utils.ReturnResponse(err.Error(), 0, nil)
	}

	return utils.ReturnResponse("商品添加成功", 200, add)

}
